package com.example.demo.control;

import com.example.demo.common.CommonResult;
import com.example.demo.pojo.User;
import com.example.demo.service.UserService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "用户接口")
@RestController
public class UserControl {

    @Autowired
    private UserService userService;

    @ApiOperation(value = "获得用户列表")
    @GetMapping("/queryUser")
    public CommonResult queryUser(){
        return CommonResult.success(userService.getAll());
    }

    @ApiOperation(value = "添加用户")
    @PostMapping("/addUser")
    public CommonResult addUser(@RequestBody User user){
        userService.add(user);
        return CommonResult.success("");
    }

    @ApiOperation(value = "删除用户")
    @GetMapping("/deleteUser")
    public CommonResult deleteUser(@RequestParam Integer user_id){
        userService.delete(user_id);
        return CommonResult.success("");
    }
}
